<template>
  <div class="container">
    <div class="class-tree">
      <edit-tree
        ref="tree"
        :treeSetting="treeSetting"
        :hideBtn="hideBtn"
        :haveRemark="false"
        @handleClickTree="handleClickTree"
        :filterNode="filterNode"
      />
    </div>
    <div class="detail-content">
      <div class="h100">
        <list-table-new v-bind="tableSetting" ref="klTable">
        </list-table-new>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getStockSummaryList,
  getStockSummaryTree,
} from "@/api/equipmentLedger/stockSummary.js";
export default {
  name: "classStandard",
  data() {
    return {
      checked: false,
      treeSetting: {
        title: "库存目录",
        data: [],
        defaultProps: {
          children: "children",
          label: "goodsFullName",
        },
        clickExpand: false,
      },
      hideBtn: true,
      classCode:null,
      currentAppid: null,
      tableSetting: {
        selectionShow: true,
        pageConfig: {
          pageCode: "stockSummary",
          userId: this.$store.getters.userInfo.namePy,
        },
        searchObj: {
          searchMethod: (params, sortStr) => {
            if (this.tableSetting.searchObj) {
              this.getTableData(params, sortStr);
            } else {
            }
          },
          queryData: {
            page: 1,
            pageSize: 15,
          },
          searchArr: [
            {
              type: "input",
              label: "商品编号",
              model: "goodsNumber",
              placeholder: "请输入",
            },
            {
              type: "input",
              label: "商品名称",
              model: "goodsFullName",
              placeholder: "请输入",
            },
            {
              type: "select",
              label: "公司名称",
              model: "companyCode",
              option: this.$store.getters.dirtData("companyCode"),
            },
            {
              type: "input",
              label: "仓库名称",
              model: "name",
              placeholder: "请输入",
            },
            {
              type: "input",
              label: "单位",
              model: "baseUnit",
              placeholder: "请输入",
            },
            {
              type: "input",
              label: "商品规格",
              model: "goodsSpec",
              placeholder: "请输入",
            }
          ],
        },
        actionList: [],
        column: [
          {
            label: "公司",
            prop: "companyCode",
            sortable: "custom",
            formatter: (row) => {
              return this.$store.getters.fineDirtDataName("companyCode",row.companyCode)
            }
          },
          {
            label: "仓库",
            prop: "name",
            sortable: "custom",
          },
          {
            label: "商品编号",
            prop: "goodsNumber",
            sortable: "custom",
          },
          {
            label: "商品名称",
            prop: "goodsFullName",
            sortable: "custom",
          },
          {
            label: "商品规格",
            prop: "goodsSpec",
            sortable: "custom",
          },
          {
            label: "数量",
            prop: "lastQty",
            sortable: "custom",
          },
          {
            label: "单位",
            prop: "baseUnit",
            sortable: "custom",
          }
        ],
        //表格方法
        tableMethods: {
          //点击行的方法
          rowClick: (row) => {},
        },
      },
    };
  },
  created() {
    this.getTreeData();
    /* 添加监听事件 */
    window.addEventListener("storage", this.updateData);
  },
  beforeDestroy() {
    /* 删除监听事件 */
    window.removeEventListener("storage", this.updateData);
  },
  mounted() {
    this.$refs.klTable.getTableConfig();
    //this.updateData();
  },
  methods: {
    //更新列表页的数据
    updateData() {
      this.$refs.klTable.searchData();
    },
    //筛选树
    filterNode(value, data) {
      if (!value) return true;
      return data.name.indexOf(value) !== -1;
    },
    //点击树节点
    handleClickTree(node) {
      this.classCode = node.classCode;
      this.updateData();
    },
    //获取分类标准树数据
    getTreeData() {
      getStockSummaryTree().then(
        (res) => {
          let data = [
            {
              id:0,
              classCode:null,
              goodsFullName:"全部",
              children:[]
            }
          ]
          data[0].children = res.data;
          this.$set(this.treeSetting, "data", data);
          this.$refs.tree.setCurrentKey(data[0].id);
        },
        (error) => {
          this.$message.error(error);
        }
      );
    },
    // 获取表格数据
    getTableData(params, sortStr) {
      let queryData = Object.assign({}, params);
      this.searchData = params;
      if (sortStr.length > 0) {
        queryData.orders = sortStr;
      }
      queryData.classCode = this.classCode;
      getStockSummaryList(queryData).then((res) => {
        this.$set(this.tableSetting, "tableData", res.data.list);
        this.$set(this.tableSetting, "totalNumber", res.data.total);
      });
    }
  },
};
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  height: calc(100% - 10px);
  background-color: white;
  display: flex;
  .class-tree {
    height: 100%;
    min-width: 300px;
  }
  .detail-content {
    height: 100%;
    width: calc(100% - 300px);
    border-left: 10px solid #f2f3f8;
    padding: 20px;
    flex: 1;
    overflow: auto;
  }
}
</style>